home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / ColorPicker.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  10.5 KB  |  346 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        ColorPicker.h
  3.  
  4.      Contains:    Color Picker package Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1987-1999 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __COLORPICKER__
  18. #define __COLORPICKER__
  19.  
  20. #ifndef __MIXEDMODE__
  21.     #include <MixedMode.h>
  22. #endif
  23.  
  24. #ifndef __QUICKDRAW__
  25.     #include <Quickdraw.h>
  26. #endif
  27.  
  28. #ifndef __CMAPPLICATION__
  29.     #include <CMApplication.h>
  30. #endif
  31.  
  32.  
  33.  
  34.  
  35. #if PRAGMA_ONCE
  36. #pragma once
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT
  44. #pragma import on
  45. #endif
  46.  
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54.  
  55. enum {
  56.                                                                 /*Maximum small fract value, as long*/
  57.     kMaximumSmallFract            = 0x0000FFFF
  58. };
  59.  
  60. enum {
  61.     kDefaultColorPickerWidth    = 383,
  62.     kDefaultColorPickerHeight    = 238
  63. };
  64.  
  65.  
  66. typedef SInt16 DialogPlacementSpec;
  67. enum {
  68.     kAtSpecifiedOrigin            = 0,
  69.     kDeepestColorScreen            = 1,
  70.     kCenterOnMainScreen            = 2
  71. };
  72.  
  73.  
  74. /* These are for the flags field in the structs below (for example ColorPickerInfo). */
  75. enum {
  76.     kColorPickerDialogIsMoveable = 1,
  77.     kColorPickerDialogIsModal    = 2,
  78.     kColorPickerCanModifyPalette = 4,
  79.     kColorPickerCanAnimatePalette = 8,
  80.     kColorPickerAppIsColorSyncAware = 16,
  81.     kColorPickerInSystemDialog    = 32,
  82.     kColorPickerInApplicationDialog = 64,
  83.     kColorPickerInPickerDialog    = 128,
  84.     kColorPickerDetachedFromChoices = 256,
  85.     kColorPickerCallColorProcLive = 512
  86. };
  87.  
  88.  
  89. #if OLDROUTINENAMES
  90. enum {
  91.                                                                 /*Maximum small fract value, as long*/
  92.     MaxSmallFract                = 0x0000FFFF
  93. };
  94.  
  95. enum {
  96.     kDefaultWidth                = 383,
  97.     kDefaultHeight                = 238
  98. };
  99.  
  100. /* These are for the flags field in the structs below (for example ColorPickerInfo). */
  101. enum {
  102.     DialogIsMoveable            = 1,
  103.     DialogIsModal                = 2,
  104.     CanModifyPalette            = 4,
  105.     CanAnimatePalette            = 8,
  106.     AppIsColorSyncAware            = 16,
  107.     InSystemDialog                = 32,
  108.     InApplicationDialog            = 64,
  109.     InPickerDialog                = 128,
  110.     DetachedFromChoices            = 256,
  111.     CallColorProcLive            = 512
  112. };
  113.  
  114. #endif  /* OLDROUTINENAMES */
  115.  
  116. /* A SmallFract value is just the fractional part of a Fixed number,
  117. which is the low order word.  SmallFracts are used to save room,
  118. and to be compatible with Quickdraw's RGBColor.  They can be
  119. assigned directly to and from INTEGERs. */
  120. /* Unsigned fraction between 0 and 1 */
  121. typedef unsigned short                     SmallFract;
  122. /* For developmental simplicity in switching between the HLS and HSV
  123. models, HLS is reordered into HSL. Thus both models start with
  124. hue and saturation values; value/lightness/brightness is last. */
  125.  
  126.  
  127. struct HSVColor {
  128.     SmallFract                         hue;                        /*Fraction of circle, red at 0*/
  129.     SmallFract                         saturation;                    /*0-1, 0 for gray, 1 for pure color*/
  130.     SmallFract                         value;                        /*0-1, 0 for black, 1 for max intensity*/
  131. };
  132. typedef struct HSVColor                    HSVColor;
  133.  
  134. struct HSLColor {
  135.     SmallFract                         hue;                        /*Fraction of circle, red at 0*/
  136.     SmallFract                         saturation;                    /*0-1, 0 for gray, 1 for pure color*/
  137.     SmallFract                         lightness;                    /*0-1, 0 for black, 1 for white*/
  138. };
  139. typedef struct HSLColor                    HSLColor;
  140.  
  141. struct CMYColor {
  142.     SmallFract                         cyan;
  143.     SmallFract                         magenta;
  144.     SmallFract                         yellow;
  145. };
  146. typedef struct CMYColor                    CMYColor;
  147.  
  148. struct PMColor {
  149.     CMProfileHandle                 profile;
  150.     CMColor                         color;
  151. };
  152. typedef struct PMColor                    PMColor;
  153. typedef PMColor *                        PMColorPtr;
  154.  
  155. struct NPMColor {
  156.     CMProfileRef                     profile;
  157.     CMColor                         color;
  158. };
  159. typedef struct NPMColor                    NPMColor;
  160. typedef NPMColor *                        NPMColorPtr;
  161. typedef struct OpaquePicker*             Picker;
  162. typedef Picker picker;
  163.  
  164. struct PickerMenuItemInfo {
  165.     short                             editMenuID;
  166.     short                             cutItem;
  167.     short                             copyItem;
  168.     short                             pasteItem;
  169.     short                             clearItem;
  170.     short                             undoItem;
  171. };
  172. typedef struct PickerMenuItemInfo        PickerMenuItemInfo;
  173. /* Structs related to deprecated API's have been pulled from this file. */
  174. /* Those structs necessary for developers writing their own color pickers... */
  175. /* have been moved to ColorPickerComponents.h. */
  176.  
  177. typedef CALLBACK_API( void , ColorChangedProcPtr )(long userData, PMColor *newColor);
  178. typedef CALLBACK_API( void , NColorChangedProcPtr )(long userData, NPMColor *newColor);
  179. typedef CALLBACK_API( Boolean , UserEventProcPtr )(EventRecord *event);
  180. typedef STACK_UPP_TYPE(ColorChangedProcPtr)                     ColorChangedUPP;
  181. typedef STACK_UPP_TYPE(NColorChangedProcPtr)                     NColorChangedUPP;
  182. typedef STACK_UPP_TYPE(UserEventProcPtr)                         UserEventUPP;
  183.  
  184. struct ColorPickerInfo {
  185.     PMColor                         theColor;
  186.     CMProfileHandle                 dstProfile;
  187.     UInt32                             flags;
  188.     DialogPlacementSpec             placeWhere;
  189.     Point                             dialogOrigin;
  190.     OSType                             pickerType;
  191.     UserEventUPP                     eventProc;
  192.     ColorChangedUPP                 colorProc;
  193.     UInt32                             colorProcData;
  194.     Str255                             prompt;
  195.     PickerMenuItemInfo                 mInfo;
  196.     Boolean                         newColorChosen;
  197.     SInt8                             filler;
  198. };
  199. typedef struct ColorPickerInfo            ColorPickerInfo;
  200.  
  201. struct NColorPickerInfo {
  202.     NPMColor                         theColor;
  203.     CMProfileRef                     dstProfile;
  204.     UInt32                             flags;
  205.     DialogPlacementSpec             placeWhere;
  206.     Point                             dialogOrigin;
  207.     OSType                             pickerType;
  208.     UserEventUPP                     eventProc;
  209.     NColorChangedUPP                 colorProc;
  210.     UInt32                             colorProcData;
  211.     Str255                             prompt;
  212.     PickerMenuItemInfo                 mInfo;
  213.     Boolean                         newColorChosen;
  214.     UInt8                             reserved;                    /*Must be 0*/
  215. };
  216. typedef struct NColorPickerInfo            NColorPickerInfo;
  217.  
  218. /*    Below are the color conversion routines.*/
  219. EXTERN_API( SmallFract )
  220. Fix2SmallFract                    (Fixed                     f)                                    THREEWORDINLINE(0x3F3C, 0x0001, 0xA82E);
  221.  
  222. EXTERN_API( Fixed )
  223. SmallFract2Fix                    (SmallFract             s)                                    THREEWORDINLINE(0x3F3C, 0x0002, 0xA82E);
  224.  
  225. EXTERN_API( void )
  226. CMY2RGB                            (const CMYColor *        cColor,
  227.                                  RGBColor *                rColor)                                THREEWORDINLINE(0x3F3C, 0x0003, 0xA82E);
  228.  
  229. EXTERN_API( void )
  230. RGB2CMY                            (const RGBColor *        rColor,
  231.                                  CMYColor *                cColor)                                THREEWORDINLINE(0x3F3C, 0x0004, 0xA82E);
  232.  
  233. EXTERN_API( void )
  234. HSL2RGB                            (const HSLColor *        hColor,
  235.                                  RGBColor *                rColor)                                THREEWORDINLINE(0x3F3C, 0x0005, 0xA82E);
  236.  
  237. EXTERN_API( void )
  238. RGB2HSL                            (const RGBColor *        rColor,
  239.                                  HSLColor *                hColor)                                THREEWORDINLINE(0x3F3C, 0x0006, 0xA82E);
  240.  
  241. EXTERN_API( void )
  242. HSV2RGB                            (const HSVColor *        hColor,
  243.                                  RGBColor *                rColor)                                THREEWORDINLINE(0x3F3C, 0x0007, 0xA82E);
  244.  
  245. EXTERN_API( void )
  246. RGB2HSV                            (const RGBColor *        rColor,
  247.                                  HSVColor *                hColor)                                THREEWORDINLINE(0x3F3C, 0x0008, 0xA82E);
  248.  
  249.  
  250. /*    GetColor() works with or without the Color Picker extension.*/
  251. EXTERN_API( Boolean )
  252. GetColor                        (Point                     where,
  253.                                  ConstStr255Param         prompt,
  254.                                  const RGBColor *        inColor,
  255.                                  RGBColor *                outColor)                            THREEWORDINLINE(0x3F3C, 0x0009, 0xA82E);
  256.  
  257.  
  258. /*    PickColor() requires the Color Picker extension (version 2.0 or greater).*/
  259. EXTERN_API( OSErr )
  260. PickColor                        (ColorPickerInfo *        theColorInfo)                        THREEWORDINLINE(0x3F3C, 0x0213, 0xA82E);
  261.  
  262. /*    NPickColor() requires the Color Picker extension (version 2.1 or greater).*/
  263. EXTERN_API( OSErr )
  264. NPickColor                        (NColorPickerInfo *        theColorInfo)                        THREEWORDINLINE(0x3F3C, 0x0227, 0xA82E);
  265.  
  266.  
  267. /* A suite of mid-level API calls have been deprecated.  Likely you never...  */
  268. /* used them anyway.  They were removed from this file and should not be... */
  269. /* used in the future as they are not gauranteed to be supported. */
  270. #if OPAQUE_UPP_TYPES
  271.     EXTERN_API(ColorChangedUPP)
  272.     NewColorChangedUPP               (ColorChangedProcPtr        userRoutine);
  273.  
  274.     EXTERN_API(NColorChangedUPP)
  275.     NewNColorChangedUPP               (NColorChangedProcPtr    userRoutine);
  276.  
  277.     EXTERN_API(UserEventUPP)
  278.     NewUserEventUPP                   (UserEventProcPtr        userRoutine);
  279.  
  280.     EXTERN_API(void)
  281.     DisposeColorChangedUPP           (ColorChangedUPP            userUPP);
  282.  
  283.     EXTERN_API(void)
  284.     DisposeNColorChangedUPP           (NColorChangedUPP        userUPP);
  285.  
  286.     EXTERN_API(void)
  287.     DisposeUserEventUPP               (UserEventUPP            userUPP);
  288.  
  289.     EXTERN_API(void)
  290.     InvokeColorChangedUPP           (long                    userData,
  291.                                     PMColor *                newColor,
  292.                                     ColorChangedUPP            userUPP);
  293.  
  294.     EXTERN_API(void)
  295.     InvokeNColorChangedUPP           (long                    userData,
  296.                                     NPMColor *                newColor,
  297.                                     NColorChangedUPP        userUPP);
  298.  
  299.     EXTERN_API(Boolean)
  300.     InvokeUserEventUPP               (EventRecord *            event,
  301.                                     UserEventUPP            userUPP);
  302.  
  303. #else
  304.     enum { uppColorChangedProcInfo = 0x000003C0 };                     /* pascal no_return_value Func(4_bytes, 4_bytes) */
  305.     enum { uppNColorChangedProcInfo = 0x000003C0 };                 /* pascal no_return_value Func(4_bytes, 4_bytes) */
  306.     enum { uppUserEventProcInfo = 0x000000D0 };                     /* pascal 1_byte Func(4_bytes) */
  307.     #define NewColorChangedUPP(userRoutine)                         (ColorChangedUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppColorChangedProcInfo, GetCurrentArchitecture())
  308.     #define NewNColorChangedUPP(userRoutine)                         (NColorChangedUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppNColorChangedProcInfo, GetCurrentArchitecture())
  309.     #define NewUserEventUPP(userRoutine)                             (UserEventUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppUserEventProcInfo, GetCurrentArchitecture())
  310.     #define DisposeColorChangedUPP(userUPP)                         DisposeRoutineDescriptor(userUPP)
  311.     #define DisposeNColorChangedUPP(userUPP)                         DisposeRoutineDescriptor(userUPP)
  312.     #define DisposeUserEventUPP(userUPP)                             DisposeRoutineDescriptor(userUPP)
  313.     #define InvokeColorChangedUPP(userData, newColor, userUPP)         CALL_TWO_PARAMETER_UPP((userUPP), uppColorChangedProcInfo, (userData), (newColor))
  314.     #define InvokeNColorChangedUPP(userData, newColor, userUPP)     CALL_TWO_PARAMETER_UPP((userUPP), uppNColorChangedProcInfo, (userData), (newColor))
  315.     #define InvokeUserEventUPP(event, userUPP)                         (Boolean)CALL_ONE_PARAMETER_UPP((userUPP), uppUserEventProcInfo, (event))
  316. #endif
  317. /* support for pre-Carbon UPP routines: NewXXXProc and CallXXXProc */
  318. #define NewColorChangedProc(userRoutine)                         NewColorChangedUPP(userRoutine)
  319. #define NewNColorChangedProc(userRoutine)                         NewNColorChangedUPP(userRoutine)
  320. #define NewUserEventProc(userRoutine)                             NewUserEventUPP(userRoutine)
  321. #define CallColorChangedProc(userRoutine, userData, newColor)    InvokeColorChangedUPP(userData, newColor, userRoutine)
  322. #define CallNColorChangedProc(userRoutine, userData, newColor)    InvokeNColorChangedUPP(userData, newColor, userRoutine)
  323. #define CallUserEventProc(userRoutine, event)                    InvokeUserEventUPP(event, userRoutine)
  324.  
  325.  
  326. #if PRAGMA_STRUCT_ALIGN
  327.     #pragma options align=reset
  328. #elif PRAGMA_STRUCT_PACKPUSH
  329.     #pragma pack(pop)
  330. #elif PRAGMA_STRUCT_PACK
  331.     #pragma pack()
  332. #endif
  333.  
  334. #ifdef PRAGMA_IMPORT_OFF
  335. #pragma import off
  336. #elif PRAGMA_IMPORT
  337. #pragma import reset
  338. #endif
  339.  
  340. #ifdef __cplusplus
  341. }
  342. #endif
  343.  
  344. #endif /* __COLORPICKER__ */
  345.  
  346.